﻿namespace EasyWeb.Web.UI
{
    using System;
    using System.Collections.Generic;
    using System.Dynamic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.UI;
    using Newtonsoft.Json;

    public class EWGrid<TModel> : EWViewComponent
    {
        private int rowCount;
        private int rowsPerPage;
        private EWGridPagerModes pagerMode;
        private int numericLinksCount;

        public EWGrid(ViewContext viewContext)
            : base(viewContext)
        {
            this.rowsPerPage = 10;
            this.pagerMode = EWGridPagerModes.NextPrevious;
            this.numericLinksCount = 5;
            this.DisplayHeader = true;
        }

        public string DataKey { get; set; }
        public IEnumerable<TModel> DataSource { get; set; }
        public int RowCount
        {
            get { return this.rowCount; }
            set
            {
                EWGuard.IsNotNegative(value, "value");
                this.rowCount = value;
            }
        }

        public bool AutoSortAndPage { get; set; }

        public bool CanPage { get; set; }
        public int RowsPerPage
        {
            get { return this.rowsPerPage; }
            set
            {
                EWGuard.IsNotZeroOrNegative(value, "value");
                this.rowsPerPage = value;
            }
        }
        public string PageFieldName { get; set; }
        public EWGridPagerModes PagerMode
        {
            get { return this.pagerMode; }
            set
            {
                EWGuard.IsDefinedEnum(value, "value");
                this.pagerMode = value;
            }
        }
        public int NumericLinksCount
        {
            get { return this.numericLinksCount; }
            set
            {
                EWGuard.IsNotZeroOrNegative(value, "value");
                this.numericLinksCount = value;
            }
        }
        public string FirstText { get; set; }
        public string PreviousText { get; set; }
        public string NextText { get; set; }
        public string LastText { get; set; }

        public bool CanSort { get; set; }
        public string DefaultSort { get; set; }
        public string SortFieldName { get; set; }
        public string SortDirectionFieldName { get; set; }

        public string TableStyle { get; set; }
        public string HeaderStyle { get; set; }
        public string FooterStyle { get; set; }
        public string RowStyle { get; set; }
        public string AlternatingRowStyle { get; set; }
        public string SelectedRowStyle { get; set; }

        public string SelectCallback { get; set; }

        public string Caption { get; set; }
        public bool DisplayHeader { get; set; }
        public bool FillEmptyRows { get; set; }
        public string EmptyRowCellValue { get; set; }
        public IEnumerable<EWGridColumn<TModel>> Columns { get; set; }

        public string AjaxUpdateCallback { get; set; }

        public string FieldNamePrefix { get; set; }
        public string SelectionFieldName { get; set; }

        protected override void WriteHtml(HtmlTextWriter writer)
        {
        }
    }
}
